package com.bw.controller;

import com.bw.domain.TbMenu;
import com.bw.domain.User;
import com.bw.utils.MenuUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Author: zhaijiaqi
 * @Date: 2025/3/12 19:41
 * @Description:
 **/
@Controller
public class MainController {


    @Autowired
    RedisTemplate redisTemplate;

    @RequestMapping("main")
    public String main(Model model, HttpSession session){
        User user = (User) session.getAttribute("user");

        List<TbMenu> tbMenuList = (List<TbMenu>) redisTemplate.opsForValue().get("tbMenuList"+user.getId());
        List<TbMenu> tbMenuList1 = MenuUtil.treeMenus(tbMenuList,null);
        model.addAttribute("list",tbMenuList1);
        return "main";
    }


}
